package mobi.greenplate.theweb.aspect;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 *
 * @author Dimitar Makariev
 */
@Aspect
public class TimeExecutionLoggingAspect {

//    @Around("execution(* mobi.greenplate.theweb..web.*.*(..)) ")
//    @Around("execution(* mobi.greenplate.theweb..*.*(..))")
//    @Around("mobi.greenplate.theweb.aspect.SystemArchitecture.inWebControllers()")
//    @Around("mobi.greenplate.theweb.aspect.SystemArchitecture.inRepositories()")
//    @Around("mobi.greenplate.theweb.aspect.SystemArchitecture.inServices()")
   // @Around("mobi.greenplate.theweb.aspect.SystemArchitecture.inSecured()")
    @Around("execution(* mobi.greenplate.theweb..web.*Controller.*(..)) ")
    public Object log(ProceedingJoinPoint call) throws Throwable {

        Logger log = Logger.getLogger(TimeExecutionLoggingAspect.class.getName());
        final String methodName = call.toShortString();

        log.log(Level.WARNING, " method [{0}] started", methodName);
        long begin = System.currentTimeMillis();
        Object point = call.proceed();
        long time = System.currentTimeMillis() - begin;
        log.log(Level.WARNING, " method [{0}] executed for: {1}ms", new Object[]{methodName, time});
        return point;
    }
}
